<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>myHouses</title>
</head>
<body>
<div class="container border-3 top-buffer" th:fragment="houseList" id="messageList" >
    <div class="row" >
        <div class="row" >
            <div class="col-md-3" th:each="house,h:${session.housepage.getList()}">
                <div class="card top-buffer">
                    <img th:src="|/${session.imagepage.getList().get(h.index)}|" class="card-img-top img-responsive center-block" alt="...">
                    <div class="card-body">
                        <h5 class="card-title" th:text="${house.housename}"></h5>
                        <p class="card-text" th:text="${house.housedescription}"></p>
                        <a  class="btn btn-outline-primary" th:onclick="loadHouseDetail([[${house.houseid}]])" href="#">查看</a><!--href="HouseInfo.html"-->
                        <a  class="btn btn-outline-success" th:onclick="updateHouse([[${house.houseid}]])" href="#">编辑</a>
                        <a  class="btn btn-outline-danger" th:onclick="deleteHouse([[${house.houseid}]])" href="#">删除</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
<div class="row">
    <div class="col-md-5"></div>
    <div class="col-md-3">
        <nav aria-label="Page navigation example" class="top-buffer">
            <ul class="pagination btn-lg">
                <li class="page-item">
                    <a class="page-link" href="#" aria-label="Previous" th:class="!${session.housepage.hasPreviousPage}? 'page-link btn disabled':'page-link' " th:onclick="loadNewPageForMyHouses([[${session.housepage.prePage}]])">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li th:class="${i}==${session.housepage.pageNum}?'active page-item':'page-item' " th:each="i : ${session.housepage.navigatepageNums}" >
                    <a class="page-link" th:onclick="loadNewPageForMyHouses([[${i}]])" >[[${i}]]</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="#" aria-label="Next" th:class="!${session.housepage.hasNextPage}? 'page-link btn disabled':'page-link' " th:onclick="loadNewPageForMyHouses([[${session.housepage.nextPage}]])">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </ul>
        </nav>
    </div>
</div>
</div>
</body>
<script>
    function loadHouseDetail(houseid) {
        $.ajax({
            url:'/house/to_houseDetail',
            type:'get',
            data:{"houseid" : houseid},
            async:true,
            dataType: "html",
            contentType: 'application/json; charset=utf-8',
            success:function (html){
                $('#allItems').html(html);
                loadComments();
            },
            error: function () {
                alert("请求错误！！");
            }
        })
    }
    function loadNewPageForMyHouses(pageNo) {
        $.ajax({
            url: '/house/to_myHouses',
            type: 'GET',
            async:true,
            data:{"pageNo":pageNo},

            success:function (data) {
                $('#allItems').html(data);
            },
            error: function () {
                alert("请求错误！！");
            }
        })
    }
    function loadComments() {
        $.ajax({
            url:'/comment/getHouseComments',
            type:'GET',
            async:true,
            dataType: "html",
            contentType: 'application/json; charset=utf-8',
            success:function (html) {
                $('#houseCommentInfo').html(html);
            },
            error: function () {
                alert("请求错误！！");
            }
        })
    }
    function deleteHouse(houseid) {
        $.ajax({
            url:'/house/delete',
            type:'GET',
            data:{"houseid":houseid},
            success:function () {
                loadPage('/house/to_myHouses');
            },
            error: function () {
                alert("请求错误！！");
            }
        })

    }
    function updateHouse(houseid) {
        $.ajax({
            url:'/house/to_updateHouse',
            type:'GET',
            data:{"houseid":houseid},
            success:function (data) {
                $('#allItems').html(data);
            },
            error: function () {
                alert("请求错误！！");
            }
        })
    }
</script>
</html>